﻿package com.sz.manager.servlet;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import com.sz.manager.bmo.IManagerBMO;
import org.springframework.web.servlet.mvc.Controller;

public class AddManager implements Controller {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected final Log logger = LogFactory.getLog(getClass());
	
	protected IManagerBMO managerBMO = null;
	
	public IManagerBMO getManagerBMO() {
		return managerBMO;
	}

	public void setManagerBMO(IManagerBMO managerBMO) {
		this.managerBMO = managerBMO;
	}

	@SuppressWarnings("unchecked")
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try {
			
			Map map = new HashMap();
			String create_manager = request.getSession().getAttribute("userid").toString();
			String region_id = request.getSession().getAttribute("regionid").toString();
			String name = request.getParameter("name");
			String passwords = request.getParameter("passwords");
			String type = request.getParameter("type");
			String descrip = request.getParameter("descrip");
			map.put("NAME", name);
			map.put("PASSWORDS", passwords);
			map.put("REGION", region_id);
			map.put("CREATE_MANAGER", create_manager);
			map.put("TYPE", type);
			map.put("DESCRIP", descrip);
			map.put("STATUS", 0);
			
			long r = managerBMO.addManager(map);
			logger.info(String.format("addManager返回:%d", r));			

			if(r > 0) {
				return new ModelAndView("/page/success.jsp");
			} else {
				return new ModelAndView("/page/failure.jsp");
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw new ServletException(e.getMessage());
		}
	}
}
